﻿using aier.business.logic;
using aier.dataaccess.model;
using aier.dataaccess.dapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using log4net;

namespace aier.wx.api.selfhost.Controllers
{
    /// <summary>
    /// 系统参数配置服务实现类
    /// </summary>
    [RoutePrefix("api/SysPara")]
    public class SysParaController : ApiController
    {
        /// <summary>
        /// 日志
        /// </summary>
        public ILog log { get; set; }
        /// <summary>
        /// 系统参数配置
        /// </summary>
        private SysParaBll sysParaBll { get; set; }

        /// <summary>
        /// 获取所有的系统参数配置信息
        /// 对应原程序 getAll()
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IHttpActionResult GetAll()
        {
            List<SysPara> keyValuePairs = sysParaBll.GetAll();
 
            return Ok<List<SysPara>>(keyValuePairs);
        }

        /// <summary>
        /// 根据参数类型与代码获取参数对像
        /// 对应原程序 getById
        /// </summary>
        /// <param name="paratype">参数类型</param>
        /// <param name="paracode">参数代码</param>
        /// <returns></returns>
        [HttpGet]
        public IHttpActionResult GetById(string paratype, string paracode)
        {
            try
            {
                SysPara sysPara = sysParaBll.GetById(paratype, paracode);
                return Ok<SysPara>(sysPara);
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
                return new ApiErrorResult(ex.Message, Request);
            }
        }
    }
}
